﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;

namespace syh876.com.Controllers
{
    public class BaseController : Controller
    {
        //记录错误信息
        // GET: /Base/


        protected override void OnException(ExceptionContext filterContext)
        {
            //Exception ex = filterContext.Exception;
            //StringBuilder sb = new StringBuilder();

            //sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            //if (filterContext.HttpContext.Request.UrlReferrer != null)
            //{
            //    sb.AppendLine("前置路径：" + filterContext.HttpContext.Request.UrlReferrer.AbsoluteUri);
            //}
            //sb.AppendLine("路径："+filterContext.HttpContext.Request.Url.AbsoluteUri);
            //sb.AppendLine("异常："+ex.Message);
            //sb.AppendLine("追踪："+ex.StackTrace);
            //sb.AppendLine("============================================");
            //Logger.Write(sb.ToString());
            //filterContext.ExceptionHandled = true;
            filterContext.Result = new RedirectResult("/Error");
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            foreach (var item in filterContext.HttpContext.Request.QueryString.AllKeys)
            {
                Common.SQLCheck.CheckKeyWord(filterContext.HttpContext.Request.QueryString[item]);
            }
            foreach (var item in filterContext.HttpContext.Request.Form.AllKeys)
            {
                Common.SQLCheck.CheckKeyWord(filterContext.HttpContext.Request.QueryString[item]);
            }
            base.OnActionExecuting(filterContext);
        }

    }
}
